package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Menu;
import cn.wolfcode.crm.mapper.MenuMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements IMenuService{
    @Autowired
    private MenuMapper menuMapper;

    public int deleteByPrimaryKey(Long id) {
        return menuMapper.deleteByPrimaryKey(id);
    }

    public int insert(Menu record) {
        return menuMapper.insert(record);
    }

    public Menu selectByPrimaryKey(Long id) {
        return menuMapper.selectByPrimaryKey(id);
    }

    public List<Menu> selectAll() {
        return menuMapper.selectAll();
    }

    public int updateByPrimaryKey(Menu record) {
        return menuMapper.updateByPrimaryKey(record);
    }
   

    //分页
    public PageResult query(QueryObject qo){
        //查总数
        int total = menuMapper.queryForCount(qo);
         if(total==0){
             return new PageResult();
         }
         //查每页数据
        List<Menu> rows = menuMapper.queryForList(qo);
        return new PageResult(rows,total);
    }

    //查父级菜单
    public List<Menu> queryRootMenu(){
        return menuMapper.queryRootMenu();
    };

}
